package com.szqhyxj.youxiangju.biz.policy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.sys.components.NavigationBar;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by leung on 2018/10/30.
 */

public class PolicyActivity extends Activity implements PolicyContract.View, NavigationBar.NavigationBarListener {

    @BindView(R.id.termInsurance)
    TextView termInsurance;
    @BindView(R.id.effectivedate)
    TextView effectivedate;
    @BindView(R.id.enddate)
    TextView enddate;
    @BindView(R.id.insured)
    TextView insured;
    @BindView(R.id.certificatetype)
    TextView certificatetype;
    @BindView(R.id.idnumber)
    TextView idnumber;
    @BindView(R.id.insurancelimit)
    TextView insurancelimit;
    @BindView(R.id.insurance)
    TextView insurance;
    @BindView(R.id.insuranceobject)
    TextView insuranceobject;
    @BindView(R.id.eneficiary)
    TextView eneficiary;
    @BindView(R.id.insuranceno)
    TextView insuranceno;
    @BindView(R.id.policybackground)
    FrameLayout policybackground;

    PolicyContract.Presenter presenter;
    @BindView(R.id.navigationBar)
    NavigationBar navigationBar;
    @BindView(R.id.title)
    LinearLayout title;

    public static void start(Activity activity) {
        Intent intent = new Intent();
        intent.setClass(activity, PolicyActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_policy);
        ButterKnife.bind(this);
        presenter = new PolicyPresenter(this);
        presenter.loadPolicyInformation();
        navigationBar.setNavigationBarListener(this);
    }

    @Override
    public void showPolicybackground() {
        title.setVisibility(View.VISIBLE);
        policybackground.setBackground(getResources().getDrawable(R.mipmap.bg_02));
    }

    @Override
    public void enShowPolicybackground() {
        title.setVisibility(View.GONE);
        policybackground.setBackground(getResources().getDrawable(R.mipmap.bg_01));
    }

    @Override
    public void showInsuranceno(String s) {
        if (isNumeric(s)){
            insuranceno.setText("NO."+s);
        }else {
            insuranceno.setText(s);
        }

    }
    public boolean isNumeric(String str){
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if( !isNum.matches() ){
            return false;
        }
        return true;
    }
    @Override
    public void showTerminsurance(String s) {
        termInsurance.setText(s);
    }

    @Override
    public void showEffectivedate(String s) {
        effectivedate.setText(s);
    }

    @Override
    public void showEnddate(String s) {
        enddate.setText(s);
    }

    @Override
    public void showInsured(String s) {
        insured.setText(s);
    }

    @Override
    public void showCertificatetype(String s) {
        certificatetype.setText(s);
    }

    @Override
    public void showIdnumber(String identNumber) {
        idnumber.setText(identNumber);
    }

    @Override
    public void showInsurancelimit(String s) {
        insurancelimit.setText(s);
    }

    @Override
    public void showInsurance(String s) {
        insurance.setText(s);
    }

    @Override
    public void showInsuranceobject(String s) {
        insuranceobject.setText(s);
    }

    @Override
    public void showEneficiary(String s) {
        eneficiary.setText(s);
    }

    @Override
    public void navToTelephone() {

    }

    @Override
    public void showFail(String s) {
        Toast.makeText(this, s, Toast.LENGTH_LONG).show();
    }

    @Override
    public void navigationLeft() {
        finish();
    }

    @Override
    public void navigationRight() {

    }
}
